package com.itheima.jobs;

import com.itheima.utils.QiniuUtils;
import org.springframework.beans.factory.annotation.Autowired;
import redis.clients.jedis.JedisPool;

import java.util.Set;

public class ClearPDFJob {

    @Autowired
    private JedisPool jedisPool;
    //清理PDF文件
    public void clearPDF(){

        Set<String> set = jedisPool.getResource().sdiff("PDF","PDF_DB");
        if(set != null){
            for (String fileName : set) {
                System.out.println("定时清理垃圾PDF： " + fileName);
                //根据图片名称从七牛云服务器删除文件
                QiniuUtils.deleteFileFromQiniu(fileName);
                //从redis集合中删除图片名称
                jedisPool.getResource().srem("PDF",fileName);
            }
            System.out.println("删除成功");
            jedisPool.getResource().del("PDF");
            jedisPool.getResource().del("PDF_DB");
        }
    }
}
